-- 客户端委托
-- Author: Colocasia
-- Date: 2018-07-11
local class = require 'class';
local handler = require 'handler';

---@class client_proxy
local M = class('client_proxy', handler);

local acc_guid;
local plr_guid;

---构造函数
---@param guid string @账号GUID
function M:ctor(guid)
    local acc = self:exc_db_cmd('account', 'find_account_by_guid', guid);
    acc_guid = acc.guid;
    plr_guid = acc.players;
    self:init_module(plr_guid);
end

---初始化模块
---@param player_guid string @玩家GUID
function M:init_module(player_guid)
    self.player = require('player').create(player_guid)
end

---获取玩家实体
---@return player
function M:entity()
    return self.player;
end

---测试
function M:login()
    self:render({}, nil, "hello client")
end

---心跳
---@return table
function M:heartbeat(msg)
    local ret =
    {
        client_info = {
            client_time = msg.client_info.client_time,
        },
        server_info = {
            server_time = os.time(),
        },
    }
    return self:render(ret);
end

return M;
